import { Button, message, Popconfirm, Input, Select } from 'antd';
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import { history } from 'umi';
import _ from 'lodash';
import request from '@/utils/request';
import apiPath from '@/utils/apiPath.js';
import Vconsole from 'vconsole';
new Vconsole()
const PageContent = () => {
  const [code, setCode] = useState("");
  const [userInfo, setUserInfo] = useState({});
  
  const getUserInfo = async(code) => {
    const hide = message.loading('正在调用');
    try {
      let nodeApi = "";
      let goApi = apiPath.WX_GET_USER_INFO;
      let res = await request(goApi, {
        method: 'GET',
        params: {
          code: code
        },
      });
      hide();
      message.success(`调用成功`);
      return res.data.data;
    } catch (error) {
      console.error(error);
      hide();
      return false;
    }
  }

  useEffect(async () => {
    if (code) {
      let res = await getUserInfo(code);
      // console.log(res);
      setUserInfo(res);
    } else {
      console.log(history.location.query.code);
      setCode(history.location.query.code);
    }
  }, [code]);

  return (
    <PageContainer>
      CODE: {code}
      {/* 获取用户信息, {userInfo.nickname} */}
    </PageContainer>
  );
};

export default PageContent;
